package com.xj;

import com.xj.config.MainConfigOfAutowired;
import com.xj.config.MainConfigOfLifeCycle;
import com.xj.dao.BookDao;
import com.xj.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 自动装配
 * @author xujiang
 * @date 2021/1/21 22:18
 */
public class IOCTest_Autowired {

    @Test
    public void test01() {
        // 创建ioc容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);
//        System.out.println("容器创建完成...");
        BookService bean = applicationContext.getBean(BookService.class);
        System.out.println(bean);
        System.out.println(applicationContext.getBean(BookDao.class));
        applicationContext.close();
    }

    /**
     * 测试Aware接口
     */
    @Test
    public void test02() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);
        System.out.println(applicationContext);
        applicationContext.close();

    }
}
